// index.js
const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'

Page({
  data: {
    codes: ['01', "02", '03', '04', '05', '06', '07']
  },

  generateLotteryNumbers(count, min, max) {
    const numbers = new Set(); // 使用Set保证数字不重复
    while (numbers.size < count) {
      const number = Math.floor(Math.random() * (max - min + 1)) + min; // 生成一个随机数
      numbers.add(number); // 添加到Set中
    }
    return Array.from(numbers).sort((a, b) => a - b); // 转换为数组并排序
  },

  // // 使用示例
  // const count = 7; // 期望的号码个数
  // const min = 1; // 最小号码
  // const max = 35; // 最大号码
  // const lotteryNumbers = generateLotteryNumbers(count, min, max);
  // console.log(lotteryNumbers);
  handleCreateCode() {
    console.log()
    const arr1 = this.generateLotteryNumbers(5,1,35)
    const arr2 = this.generateLotteryNumbers(2,1,12)
    const arr3 = arr1.concat(arr2).map(item=>{
      return item<10?'0'+item:item
    })
    this.setData({ codes: arr3})
  },
  bindViewTap() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  onChooseAvatar(e) {
    const {
      avatarUrl
    } = e.detail
    const {
      nickName
    } = this.data.userInfo
    this.setData({
      "userInfo.avatarUrl": avatarUrl,
      hasUserInfo: nickName && avatarUrl && avatarUrl !== defaultAvatarUrl,
    })
  },
  onInputChange(e) {
    const nickName = e.detail.value
    const {
      avatarUrl
    } = this.data.userInfo
    this.setData({
      "userInfo.nickName": nickName,
      hasUserInfo: nickName && avatarUrl && avatarUrl !== defaultAvatarUrl,
    })
  },
  getUserProfile(e) {
    // 推荐使用wx.getUserProfile获取用户信息，开发者每次通过该接口获取用户个人信息均需用户确认，开发者妥善保管用户快速填写的头像昵称，避免重复弹窗
    wx.getUserProfile({
      desc: '展示用户信息', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
      success: (res) => {
        console.log(res)
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    })
  },
})